<?php
/**
 * This file is part of Task Agile.
 * Task Agile is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License.
 * Task Agile is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Task Agile.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category   TaskAgile
 * @package    Controller
 * @copyright  Copyright (c) 20010-2010 Estrada Virtual (http://estradavirtual.com.br)
 * @license    http://www.gnu.org/licenses/gpl.txt GPLv3
 * @version    $Id$
*/
class CronController extends App_Controller_Action
{
    public function indexAction()
    {
        $this->_sendEmailTarefasSemana();
        die;
    }

    private function _sendEmailTarefasSemana()
    {
        $conteudo = $this->view->action('tarefas-semana', 'relatorio', 'corporativo', array('disabledLayout' => true));
        $this->view->emailBody = $conteudo;
        $this->view->addBasePath(APPLICATION_PATH . '/layouts/default');
        $emailBody = $this->view->render('email.phtml');

        // Email
        $mail = new Zend_Mail('UTF8');
        $mail->setSubject('[CEV] Tarefas da semana');
        $mail->setBodyHtml($emailBody);

        // Usuarios
        $modelEmpresa = new Model_Cliente();
        $rowEstrada = $modelEmpresa->find(1)->current();

        $rowSetFuncionarios = $rowEstrada->findModel_UsuarioViaModel_ClienteUsuario();

        foreach ($rowSetFuncionarios as $rowFuncionario) {
            $mail->addTo($rowFuncionario->st_email, $rowFuncionario->st_nome);
        }
        $mail->send();
    }
}